import {
  PrimaryGeneratedColumn,
  Column,
  Entity,
  JoinColumn,
  CreateDateColumn,
  ManyToOne,
} from 'typeorm';
import { Exclude } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { Role } from '@/modules/businessModule/role/assets/role.entity';
import {
  Constant_Enum_Enum_UserAdmin_Status,
  IConstant_Enum_Type_UserAdmin_Status,
} from '@/common/constants/enum';

@Entity('useradmin')
export class UserAdmin {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  @ApiProperty({ description: '用户名' })
  userName: string;

  @Column()
  @Exclude()
  @ApiProperty({ description: '密码' })
  password: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '头像' })
  avatar?: string;

  @Column({ default: Constant_Enum_Enum_UserAdmin_Status.UserAdmin_Status_Enable })
  @ApiProperty({ description: '状态' })
  statusUser: IConstant_Enum_Type_UserAdmin_Status;

  @Exclude()
  @CreateDateColumn({
    type: 'datetime',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP(0)',
    onUpdate: 'CURRENT_TIMESTAMP(0)',
  })
  @ApiProperty({ description: '创建时间' })
  createTime: Date;

  @ManyToOne(() => Role, (role) => role.userAdmin)
  @JoinColumn()
  @ApiProperty({ description: '角色', type: () => Role })
  role: Role;
}
